09. Running Java Applications

Running Java Applications

ND079 JPND C3 L1 A07 Running Java Applications

Originally, Java bytecode was executed directly by the JVM, one line at a time. That means the JVM functioned as an interpreter. As of Java 1.3, the JVM pre-compiles parts of the bytecode into machine code and saves it for later use.

Interpreter vs. Compilation

Interpreter:

  • Parses Bytecode Line-by-Line
  • Performs the operation requested by each bytecode statement
  • Starts fast, but runs slower

Compilation:

  • JVM compiles bytecode into machine code in advance
  • Saves machine code for reuse
  • Takes longer to start, but runs faster after beginning

Just-In-Time Compilation

Java uses something called a HotSpot VM to monitor the code while it is executing. This VM uses a profile to optimize the compilation process and produce more efficient machine code.

The HotSpot JVM

The HotSpot JVM

Tiered Compilation

As of Java 8, the JVM will use two different compilers. The Client Compiler, or C1, quickly compiles the bytecode into machine code and lets the application start right away, while the **Server Compiler, **or C2, recompiles the application based on the information from the profiler.

Resources

Hotspot performance enhancements: https://docs.oracle.com/en/java/javase/15/vm/java-hotspot-virtual-machine-performance-enhancements.html

Compiler Optimization: https://docs.oracle.com/javacomponents/jrockit-hotspot/migration-guide/comp-opt.htm